package eg.ci.mvn.service.demo.facade;


import cn.hutool.core.util.StrUtil;
import eg.ci.mvn.service.api.constant.DemoConstant;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import static eg.ci.mvn.service.api.model.param.ParkingCardParam.CardGroup;
import static eg.ci.mvn.service.api.model.param.ParkingMemberParam.CardMember;
/**
 *
 */
@Component
public class CardServiceFacade {

    /**
     * 返回临停卡
     * @param gateCode
     * @return
     */
    public CardGroup tempCardGroup(String gateCode) {
        return DemoConstant.GLOBAL.getCardGroups().stream().parallel()
                .filter(c -> c.getClassify() == 1)
                .filter(c -> StrUtil.splitTrim(c.getRegionCode(), ",").contains(gateCode.substring(0, gateCode.length() - 2)))
                .findFirst().orElse(null);
    }

    /**
     * 返回会员卡卡
     * @param cardGroupId
     * @return
     */
    public CardGroup cardGroup(String cardGroupId ) {
        return DemoConstant.GLOBAL.getCardGroups().stream().parallel()
                .filter(c -> Objects.equals(c.getId(), cardGroupId))
                .findFirst().orElse(null);
    }

    /**
     * 返回会员，如果存在
     * @param gateCode
     * @param carPlateNo
     * @param carPlateColor
     * @return
     */
    public CardMember carMember(String gateCode, String carPlateNo, String carPlateColor) {

        List<CardMember> match = DemoConstant.GLOBAL.getCardMembers().stream().parallel()
                .filter( m -> m.getCarPlateNo().equals(carPlateNo))
                .filter( m -> m.getCarPlateColor().equals(carPlateColor))
                .collect(Collectors.toList());

        return  match.stream().findFirst().orElse(null);
    }
}
